<template>
  <div class="dashboard-editor-container">
    <el-row>
      <el-col :span="12">
        <p>
          <b style="margin-right: 10px">当前小程序:</b>
          <el-select v-model="extAppid" placeholder="请选择小程序"  @change="setExtAppid" clearable size="small">
            <el-option
              v-for="applet in appletList"
              :key="applet.appid"
              :label="applet.nickName"
              :value="applet.appid"
            />
          </el-select>
        </p>
      </el-col>
    </el-row>
    <el-row :gutter="40" class="panel-group">
      <el-col :xs="12" :sm="12" :lg="12" class="card-panel-col">
        <div class="card-panel" >
          <div class="card-panel-icon-wrapper icon-money" >
            <svg-icon icon-class="money" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description" style="width: 25%;float: left">
            <div class="card-panel-text">
              今日销售额
            </div>
            <count-to :start-val="dataModel.saleToday" :end-val="dataModel.saleToday" :duration="3200" class="card-panel-num" />
          </div>
          <div class="card-panel-description" style="width: 25%;float: left">
            <div class="card-panel-text">
              昨日销售额
            </div>
            <count-to :start-val="dataModel.saleYesterday" :end-val="dataModel.saleYesterday" :duration="3200" class="card-panel-num" />
          </div>
          <div class="card-panel-description" style="width: 25%;float: left">
            <div class="card-panel-text">
             销售总额
            </div>
            <count-to :start-val="dataModel.saleTotal" :end-val="dataModel.saleTotal" :duration="3200" class="card-panel-num" />
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="12" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-shopping">
            <svg-icon icon-class="shopping" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description" style="width: 25%;float: left">
            <div class="card-panel-text">
              今日订单
            </div>
            <count-to :start-val="dataModel.orderToday" :end-val="dataModel.orderToday" :duration="3600" class="card-panel-num" />
          </div>
          <div class="card-panel-description" style="width: 25%;float: left">
            <div class="card-panel-text">
              昨日订单
            </div>
            <count-to :start-val="dataModel.orderYesterday" :end-val="dataModel.orderYesterday" :duration="3600" class="card-panel-num" />
          </div>
          <div class="card-panel-description" style="width: 25%;float: left">
            <div class="card-panel-text">
              订单总量
            </div>
            <count-to :start-val="dataModel.orderTotal" :end-val="dataModel.orderTotal" :duration="3600" class="card-panel-num" />
          </div>
        </div>
      </el-col>
    </el-row>
    <el-row :gutter="40" class="panel-group">
      <el-col :xs="6" :sm="6" :lg="3" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-description" >
            <div class="card-panel-text">
              待付款
            </div>
            <count-to :start-val="dataModel.pending" :end-val="dataModel.pending" :duration="3600" class="card-panel-num" />
          </div>
        </div>
      </el-col>
      <el-col :xs="6" :sm="6" :lg="3" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-description" >
            <div class="card-panel-text">
              待发货
            </div>
            <count-to :start-val="dataModel.sendGoods" :end-val="dataModel.sendGoods" :duration="3600" class="card-panel-num" />
          </div>
        </div>
      </el-col>
      <el-col :xs="6" :sm="6" :lg="3" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-description">
            <div class="card-panel-text">
              待收货
            </div>
            <count-to :start-val="dataModel.delivered" :end-val="dataModel.delivered" :duration="3600" class="card-panel-num" />
          </div>
        </div>
      </el-col>
      <el-col :xs="6" :sm="6" :lg="3" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-description">
            <div class="card-panel-text">
              售后待审核
            </div>
            <count-to :start-val="dataModel.orderService" :end-val="dataModel.orderService" :duration="3600" class="card-panel-num" />
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="12" class="card-panel-col">
        <el-row>
          <el-col :span="6">
            <div class="card-panel"  >
              <div class="card-panel-icon-wrapper icon-money" style="font-size: 24px;" @click="$router.push({ path: '/page/pgPage' });"  >
                <svg-icon icon-class="dashboard" class-name="card-panel-icon" style="font-size: 30px" />店铺装修
              </div>
            </div>
          </el-col>
          <el-col :span="6">
            <div class="card-panel"  >
              <div class="card-panel-icon-wrapper icon-money" style="font-size: 24px;" @click="$router.push({ path: '/goods/good' });" >
                <svg-icon icon-class="list" class-name="card-panel-icon" style="font-size: 30px" />商品管理
              </div>
            </div>
          </el-col>
          <el-col :span="6">
            <div class="card-panel"  >
              <div class="card-panel-icon-wrapper icon-money" style="font-size: 24px;"  @click="$router.push({ path: '/order/orderall' });">
                <svg-icon icon-class="shopping" class-name="card-panel-icon" style="font-size: 30px" />订单管理
              </div>
            </div>
          </el-col>
          <el-col :span="6">
            <div class="card-panel"  >
              <div class="card-panel-icon-wrapper icon-money" style="font-size: 24px;" @click="$router.push({ path: 'order/orderService' });" >
                <svg-icon icon-class="form" class-name="card-panel-icon" style="font-size: 30px" />售后订单
              </div>
            </div>
          </el-col>
        </el-row>

      </el-col>
    </el-row>

    <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
      <div>近7日交易走势</div>
      <line-chart :chart-data="dataModel" />
    </el-row>



  </div>
</template>

<script>
import PanelGroup from './dashboard/PanelGroup'
import LineChart from './dashboard/LineChart'
import RaddarChart from './dashboard/RaddarChart'
import PieChart from './dashboard/PieChart'
import BarChart from './dashboard/BarChart'
import {getExtAppid, listAuthorityApplet, setExtAppid} from "@/api/wechat/applet";
import CountTo from 'vue-count-to'
import {orderDataCount} from "../api/order/order";

export default {
  name: 'Index',
  components: {
    CountTo,
    PanelGroup,
    LineChart,
    RaddarChart,
    PieChart,
    BarChart
  },
  data() {
    return {
      extAppid:'1',
      appletList:[],
      dataModel:{}

    }
  },
  created() {
    this.getExtAppid();
    this.getAuthorityApplet()
    this.getShopCount();
  },
  methods: {
    getExtAppid(){
      getExtAppid().then(res=>{
        this.extAppid=res.data
      })
    },
    setExtAppid(){
      setExtAppid(this.extAppid);
    },
    getAuthorityApplet(){
      listAuthorityApplet().then(res=>{
        this.appletList = res.data;
      })
    },
    getShopCount(){
      orderDataCount().then(res=>{
        this.dataModel = res.data;
        console.log(this.dataModel)
      })
    },
    handleSetLineChartData(type) {
      this.lineChartData = lineChartData[type]
    }
  }
}
</script>

<style lang="scss" scoped>
.dashboard-editor-container {
  padding: 32px;
  background-color: rgb(240, 242, 245);
  position: relative;

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;
  }
}

@media (max-width:1024px) {
  .chart-wrapper {
    padding: 8px;
  }
}
</style>
<style lang="scss" scoped>
.panel-group {
  margin-top: 18px;

  .card-panel-col {
    margin-bottom: 32px;
  }

  .card-panel {
    height: 108px;
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
    border-color: rgba(0, 0, 0, .05);

    &:hover {
      .card-panel-icon-wrapper {
        color: #fff;
      }

      .icon-people {
        background: #40c9c6;
      }

      .icon-message {
        background: #36a3f7;
      }

      .icon-money {
        background: #f4516c;
      }

      .icon-shopping {
        background: #34bfa3
      }
    }

    .icon-people {
      color: #40c9c6;
    }

    .icon-message {
      color: #36a3f7;
    }

    .icon-money {
      color: #f4516c;
    }

    .icon-shopping {
      color: #34bfa3
    }

    .card-panel-icon-wrapper {
      float: left;
      margin: 14px 0 0 14px;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }

    .card-panel-icon {
      float: left;
      font-size: 48px;
    }

    .card-panel-description {
      font-weight: bold;
      margin: 26px;
      margin-left: 0px;
      text-align: center;

      .card-panel-text {
        line-height: 18px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 12px;
      }

      .card-panel-num {
        font-size: 20px;
      }
    }
  }
}

@media (max-width:550px) {
  .card-panel-description {
    display: none;
  }

  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}
</style>
